from apps.common.base.dao import BaseDao
from apps.system.lessee.serializers import *
from decimal import Decimal
from django.db.models import F

class LesseeDao(BaseDao):
    MODEL_CLASS = Lessee
    SERI_CLASS = LesseeBaseSerializer

    def getLessee(self):
        return self.findAll().first()

    def addWallet(self, scene, value):
        # print('增加积分', scene, obj, value)
        value = Decimal(value).quantize(Decimal("0.00"))
        if value == 0:
            return
        value = value.quantize(Decimal("0.00"))
        if scene == 'freePoolDay':
            obj = LesseeDao().getLessee()
            obj.freePoolDay = F('freePoolDay') + value
            obj.save()
        elif scene == 'freePoolMonth':
            obj = LesseeDao().getLessee()
            obj.freePoolMonth = F('freePoolMonth') + value
            obj.save()
        elif scene == 'supplyAwards':
            obj = LesseeDao().getLessee()
            obj.supplyAwards = F('supplyAwards') + value
            obj.save()
        elif scene == 'helpFundPool':
            obj = LesseeDao().getLessee()
            obj.helpFundPool = F('helpFundPool') + value
            obj.save()
        elif scene == 'grossProfit':
            obj = LesseeDao().getLessee()
            obj.grossProfit = F('grossProfit') + value
            obj.save()
        elif scene == 'operationAwardPool':
            obj = LesseeDao().getLessee()
            obj.operationAwardPool = F('operationAwardPool') + value
            obj.save()
        else:
            print('payway不存在')

    def subWallet(self, scene, value):
        # print('减少积分', scene, obj, value)
        value = Decimal(value).quantize(Decimal("0.00"))
        if scene == 'freePoolDay':
            obj = LesseeDao().getLessee()
            obj.freePoolDay = F('freePoolDay') - value
            obj.save()
        elif scene == 'freePoolMonth':
            obj = LesseeDao().getLessee()
            obj.freePoolMonth = F('freePoolMonth') - value
            obj.save()
        elif scene == 'helpFundPool':
            obj = LesseeDao().getLessee()
            obj.helpFundPool = F('helpFundPool') - value
            obj.save()
        elif scene == 'grossProfit':
            obj = LesseeDao().getLessee()
            obj.grossProfit = F('grossProfit') - value
            obj.save()
        elif scene == 'operationAwardPool':
            obj = LesseeDao().getLessee()
            obj.operationAwardPool = F('operationAwardPool') - value
            obj.save()
        else:
            print('payway不存在')